package com.wxtwxt.ruralmall.order.vo;

import com.sun.org.apache.xpath.internal.operations.Bool;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author Wxt
 * @create 2023-04-26 22:42
 */
public class OrderConfirmVo {
    @Setter @Getter
    private List<MemberAddressVo> address;
    @Setter @Getter
    private List<OrderItemVo> items;
    @Setter @Getter
    private Integer integration;
    @Setter @Getter
    private String orderToken;
    @Setter @Getter
    private Map<Long, Boolean> stocks;

    private BigDecimal total;

    public BigDecimal getTotal() {
        BigDecimal sum = new BigDecimal(0L);
        if(items != null && items.size() > 0) {
            for (OrderItemVo item : items) {
                BigDecimal result = item.getPrice().multiply(new BigDecimal(item.getCount()));
                sum = sum.add(result);
            }
        }
        return sum;
    }

    private BigDecimal payPrice;

    public BigDecimal getPayPrice() {
        BigDecimal sum = new BigDecimal(0L);
        if(items != null && items.size() > 0) {
            for (OrderItemVo item : items) {
                BigDecimal result = item.getPrice().multiply(new BigDecimal(item.getCount()));
                sum = sum.add(result);
            }
        }
        return sum;
    }

    private Integer count;

    public Integer getCount() {
        Integer num = 0;
        if(items != null && items.size() > 0) {
            for (OrderItemVo item : items) {
                num += item.getCount();
            }
        }
        return num;
    }
}
